package com.csu.csumall.service.imp;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csu.csumall.entity.User;
import com.csu.csumall.mapper.UserMapper;
import com.csu.csumall.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service("userService")
public class UserServiceImp extends ServiceImpl<UserMapper, User> implements IUserService {

    private final UserMapper userMapper;

    @Autowired
    public UserServiceImp(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public boolean isUnusedPhone(String phone) {

        return userMapper.selectCount(
                Wrappers.<User>query().eq("phone", phone)
        ) == 0;
    }

    @Override
    public boolean isUnusedEmail(String email) {
        return userMapper.selectCount(
                Wrappers.<User>query().eq("email", email)
        ) == 0;
    }

    @Override
    public boolean isUnusedUsername(String username) {
        return userMapper.selectCount(
                Wrappers.<User>query().eq("username", username)
        ) == 0;
    }

}
